<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/double-date.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadify/uploadify.css"/>
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/double-date.js"></script>
</head>

<script>
var pnum = {$pnum};
{if condition="(!isset($search)) OR (!$search)"}
var url = "/{$Request.module}/shop_custom/lst.html?page="+pnum;
{else/}
var url = "/{$Request.module}/shop_custom/search.html?page="+pnum;
{/if}
var updateUrl = "{:url('shop_custom/edit')}";

var gurl = "/{$Request.module}";
</script>

<body class="gray-bg">
<style>
.col-sm-6 p{line-height:32px; font-size:14px;}
</style>

<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑推荐位</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">推荐位名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="custom_name" value="{$coms.custom_name}" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">调用类型：</label>
                                <div class="col-sm-6" id="atype">
                                        <label class="radio-inline"><input type="radio" name="type" {if condition="$coms['type'] eq 1"}checked="checked"{/if} value="1">商品信息</label>
                                        <label class="radio-inline"><input type="radio" name="type" {if condition="$coms['type'] eq 2"}checked="checked"{/if} value="2">服务商品信息</label>
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>    
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="sort" value="50" value="{$coms.sort}" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>                                              
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">选择推荐信息：</label>
                                <div class="col-sm-6">
                                <button type="button" class="btn btn-success" onclick="selectGoods();">选择信息</button>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">已选择的信息：</label>
                                <div class="col-sm-8">
	                            <table class="table table-hover table-bordered">
	                            <thead class="biaoge">
                                {switch name="coms.type"}
                                {case value="1"}
                                <tr>
                                <th style="width:30%">商品名称</th>
                                <th style="width:20%">缩略图</th>
                                <th style="width:15%">所属分类</th>
                                <th style="width:20%">金额</th>
                                <th style="width:15%">操作</th>
                                </tr>
                                {/case}
                                {case value="2"}

                                {/case}                        
                                {/switch}
	                            </thead>
                                <tbody id="goods_list">
                                {switch name="coms.type"}
                                {case value="1"}
                                {foreach name="cominfo" item="v"}
                                <tr>
                                    <td style="display:none;"><input type="checkbox" class="text_id" name="goods_id[]" checked="checked" value="{$v.id}"></td>
                                    <td>{$v.goods_name}</td>
                                    <td><img src="{$v.thumb_url}" width="100px" height="100px"/></td>
                                    <td>{$v.cate_name}</td>
                                    <td>{$v.shop_price}&nbsp;元</td>                                                                   
                                    <td><button type="button" class="btn btn-danger btn-xs" onclick="$(this).parent().parent().remove();"><i class="fa fa-close"></i>&nbsp;移除</button></td>
                                </tr>
                                {/foreach}
                                {/case}
                                {case value="2"}
                                
                                {/case}                               
                                {/switch}
                                </tbody>	
	                            </table>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            
                            <input type="hidden" name="id" value="{$coms.id}" />      
                                                                                                                      
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit" id="doSubmit" style="margin-right:100px;">保存内容</button>
                                    <button type="reset" class="btn btn-default">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <div id="jianwei" style="display:none;">{$coms.type}</div>
    <div id="jianwei2" style="display:none;">{$coms.type}</div>

    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script type="text/javascript" src="__PUBLIC__/uploadify/jquery.uploadify.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>

	<script>
    	$(function(){
    		$('input:radio[name=type]').change(function(){
            	var typeid = $(this).val();
            	var type_id = $('#jianwei').text();
            	if(type_id && type_id != typeid){
            		$('.biaoge').html('');
            		$('#goods_list').html('');
            		var type_id2 = $('#jianwei2').text();
            		if(typeid == type_id2){
                		var id = $('input[name=id]').val();
                	   	$.ajax({
                			url:"{:url('custom/getcusinfo')}",
                			type:'POST',
                			data:{'id':id},
                			dataType:'json',
                			success:function(data){
                			    if(data.status == 1){ 
                                    if(data.type == 1){
                                  	    var html = '<tr><th style="width:30%">商品名称</th><th style="width:20%">缩略图</th><th style="width:15%">所属分类</th><th style="width:20%">金额</th><th style="width:15%">操作</th></tr>';
	                       	    	    var html2 = '';
	                    	    	    $.each(data.info,function(index,value){
                                            html2+='<tr><td style="display:none;"><input type="checkbox" class="text_id" name="goods_id[]" checked="checked" value="'+value.id+'"></td><td>'+value.goods_name+'</td><td><img src="/'+value.shop_name+'" width="100px" height="100px"/></td><td>'+value.cate_name+'</td><td>'+value.shop_price+'</td><td><button type="button" class="btn btn-danger btn-xs" onclick="$(this).parent().parent().remove();"><i class="fa fa-close"></i>&nbsp;移除</button></td></tr>';
	                    	    	    });
                                	    $('.biaoge').html(html);
                                	    $('#goods_list').html(html2);
                                    }else if(data.type == 2){

                                    }
                			    }
                			},
                			error:function(){
                				layer.msg('系统错误，请重试', {icon: 2,time: 2000});
                			}
                		});
            		}
            	}
                $('#jianwei').text(typeid);
            });
    		
    	    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        	$('#form').validate({
        		errorElement : 'span',
	        	debug: true,//只验证不提交表单
	            //layer ajax提交表单
	            submitHandler:function(){	            	
	                // 序列化 表单数据 后提交 ，太简洁了
	                post(updateUrl,'POST',$('#form').serialize(),1);
	                return false;
	            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法
	                
	        	rules:{
	        		custom_name:{required:true},
	        	    type:{required:true},
	        		sort:{
	        			required:true,
	        			digits:true
	        	    }
	        	},
	        		
	        	messages:{
	        		custom_name:{required:icon+'必填'},
	        		type:{required:icon+'必选'},
	                sort:{
	                	required:icon+'必填',
	                	digits:icon+'排序必须是整数'
	                }
	        	}
            });
      });    	
  	  
      function selectGoods(){
    	  var type = $("input:radio[name=type]:checked").val();
    	  
    	  if(!type){
    		  layer.msg('请选择调用类型', {icon: 2,time: 2000});
			  return false;
    	  }
    	  
          var goods_id = new Array();
          //过滤选择重复信息
          $('input[name*=goods_id]').each(function(i,o){
              goods_id.push($(o).val());
          });
          if(type == 1){
        	  var html = '<tr><th style="width:30%">商品名称</th><th style="width:20%">所属商家</th><th style="width:15%">所属分类</th><th style="width:20%">金额</th><th style="width:15%">操作</th></tr>';
        	  var goodsurl = gurl+"/getgoods/lst/goods_id/"+goods_id;
        	  $('.biaoge').html(html);
          }else if(type == 2){
        	  return false;
          }else{
        	  return false;
          }
          layer.open({
              type: 2,
              title: '选择推荐信息',
              shadeClose: true,
              shade: 0.3,
              area: ['70%', '80%'],
              content: goodsurl,
          });
      }

      function call_backgoods(table_html){
          layer.closeAll('iframe');
          $('#goods_list').append(table_html);
      }
    	
      function cl(){
    	  location.href = url;
      }
    </script>

</body>
</html>